package com.oriental.manage.service.specially.Impl;

import com.oriental.check.commons.util.BeanMapperUtil;
import com.oriental.manage.core.response.ResponseDTO;
import com.oriental.manage.core.utils.StringUtils;
import com.oriental.manage.dao.specially.ReissueApplyMapper;
import com.oriental.manage.pojo.specially.ReissueApply;
import com.oriental.manage.service.specially.ReissueApplyService;
import com.oriental.opcif.common.util.AssertResultUtils;
import com.oriental.paycenter.commons.utils.ConvertUtil;
import com.oriental.paycenter.commons.utils.DateUtil;
import com.oriental.paycenter.commons.utils.RandomMath;
import com.oriental.riskfront.api.enums.MessageStatus;
import com.oriental.riskfront.api.enums.ProcessCode;
import com.oriental.riskfront.api.model.specially.ReissueApplyDto;
import com.oriental.riskfront.api.model.specially.ResponseModel;
import com.oriental.riskfront.api.service.ReissueApplyInterface;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.ConvertUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Author: yutao
 * Date: 2017/5/2
 * Time: 17:58
 * Desc：
 */
@Service
@Slf4j
public class ReissueApplyServiceImpl implements ReissueApplyService{

    @Autowired
    private ReissueApplyMapper reissueApplyMapper;

    @Autowired
    private ReissueApplyInterface reissueApplyInterface;

    @Override
    public List<ReissueApply> queryPage(ReissueApply reissueApply) {
        return reissueApplyMapper.queryPage(reissueApply);
    }


    public void addReissueApply(ReissueApply reissueApply,ResponseDTO<String> responseDTO) {
        ReissueApplyDto reissueApplyDto = BeanMapperUtil.objConvert(reissueApply, ReissueApplyDto.class);
        ResponseModel<String> responseModel = reissueApplyInterface.sendReissueApplyMsg(reissueApplyDto);
        log.info("黑名单风险提示信息申请补发响应:{}",responseModel);
        if(responseModel.isSuccess()){
            String xml = responseModel.getResult();
            String status = StringUtils.getSubMessage(xml, "<ResultStatus>", "</ResultStatus>");
            String resultCode = StringUtils.getSubMessage(xml, "<ResultCode>", "</ResultCode>");
            //状态为未知 对应上报中状态 可再次提交申请
            responseDTO.setCode(status);
            responseDTO.setMsg(ProcessCode.getCode(resultCode));
        }else {
            responseDTO.setSuccess(false);
            responseDTO.setCode(responseModel.getErrorCode());
            responseDTO.setMsg(responseModel.getErrorMsg());
        }


    }

}
